package cn.xcyy.itcc.web.controller;

import cn.xcyy.itcc.dto.SmsCodeDto;
import cn.xcyy.itcc.result.JSONResult;
import cn.xcyy.itcc.service.IVerifyCodeSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeSerivce verifyCodeSerivce;

    @GetMapping("/imageCode/{key}")
    public JSONResult imgKey(@PathVariable("key") String key){
        try {
            String base64Str = verifyCodeSerivce.imgKey(key);
            return JSONResult.error().setData(base64Str);
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.error();
        }
    }


    @PostMapping("/sendSmsCode")
    public JSONResult smsCode(@RequestBody SmsCodeDto smsCodeDto){
        verifyCodeSerivce.smsCode(smsCodeDto);
        return new JSONResult();
    }


}
